package com.sptpc.demo.service.impl;

import com.sptpc.demo.model.Student;
import com.sptpc.demo.repository.StudentRepository;
import com.sptpc.demo.service.IStudentService;

import java.util.List;

public class StudentJpaService implements IStudentService {
    public StudentRepository studentRepository;
    @Override
    public List<Student> getAllStudents() {
        return studentRepository.findAll();
    }

    @Override
    public void addNewStudent(Student student) {
        studentRepository.save(student);
    }

    @Override
    public void deleteStudent(Integer id) {
        studentRepository.deleteById(id);
    }

    @Override
    public Student getStudentById(Integer id) {
        return studentRepository.findById(id).orElse(null);
    }

    @Override
    public void updateStudent(Student student) {
        studentRepository.save(student);
    }
}
